# Uses untortured, independently replicated data for re-analysis of:
#@ARTICLE{muller:seligson:1987,
#  author       = {Edward N. Muller and Mitchell A. Seligson},
#  title        = {Inequality and Insurgency},
#  journal      = {American Political Science Review},
#  volume       = 82,
#  number       = 2,
#  month        = {June},
#  year         = 1987,
#  pages        = {425-452},
#}

wd<-c("C:/Documents and Settings/Administrator/My Documents/My Classes/PSCI 510/Rcode/L6/mullerseligson")
setwd(wd)
library(foreign)
ms<-read.table("msrepl87.asc",header=T)
rownames(ms)<-ms$country
names(ms)
plot(ms$deaths75)

ms.out<-glm(deaths75~upper20+energypc+sanctions70, data=ms,family="poisson")
summary(ms.out)
plot(ms.out)


plot(fitted(ms.out),rstandard(ms.out),las=1)
abline(h=0)
abline(h=2)
abline(h=-2)
plot(predict(ms.out),rstandard(ms.out),las=1)
abline(h=0)
abline(h=2)
abline(h=-2)

library(MASS)
ms.out<-glm.nb(deaths75~upper20+energypc+sanctions70, data=ms)
summary(ms.out)
plot(ms.out)

library(Zelig)

z.out <- zelig(deaths75~upper20+energypc+sanctions70, data=ms, model = "negbin")
summary(z.out)

# Set values for the explanatory variables to their default mean values: 
x.out <- setx(z.out, upper20 = 49.67, energypc = 1774,sanctions70 = 12 )

# Simulate fitted values: 
s.out <- sim(z.out, x = x.out)
summary(s.out)
plot(s.out)
